<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script src="./vue.js"></script>
    <div id="app">
        <!--3、使用子组件-->
        <App></App>
    </div>

    <script>
        const bus = new Vue();
        // 父组件 provide来提供变量,然后在自组建中通过inject来注入变量，无论组件嵌套多深
        // 中央事件总线 bus
        Vue.component('B',{
            data(){
                return {
                    count: 0
                }
            },
            inject: ['msg'],
            created(){
                console.log(this.msg);
            },
            template:`
               <div>
                    {{msg}}
                </div>
            `,
        
        })

        Vue.component('A',{
            data(){
                return {
                    
                }
            },
            created() {
                // console.log(this.$parent.$parent);
                // console.log(this.$children);
            },
            template:`
                <div>
                    <B></B>
                </div>
            `,
            
        })

        // App作为父组件
        const App = {
            data() {
                return {
                   title: "老爹",
                }
            },
            provide(){
                return {
                    msg: '老爹的数据'
                }
            },
            template: `
               <div>
                    <A></A>
               </div>
            `,
        }

        new Vue({
            el: '#app',
            data: {

            },
            components:{
                // 2. 挂载子组件
                App
            }

        })
    </script>
</body>
</html>